home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / controls / RadioButtonGroup.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  7.4 KB  |  262 lines

  1. package mx.controls
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import mx.core.Application;
  6.    import mx.core.IFlexDisplayObject;
  7.    import mx.core.IMXMLObject;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    
  11.    use namespace mx_internal;
  12.    
  13.    public class RadioButtonGroup extends EventDispatcher implements IMXMLObject
  14.    {
  15.       mx_internal static const VERSION:String = "3.2.0.3958";
  16.       
  17.       private var radioButtons:Array;
  18.       
  19.       private var _selection:RadioButton;
  20.       
  21.       private var _selectedValue:Object;
  22.       
  23.       private var document:IFlexDisplayObject;
  24.       
  25.       private var _labelPlacement:String = "right";
  26.       
  27.       private var indexNumber:int = 0;
  28.       
  29.       public function RadioButtonGroup(param1:IFlexDisplayObject = null)
  30.       {
  31.          radioButtons = [];
  32.          super();
  33.       }
  34.       
  35.       [Bindable("enabledChanged")]
  36.       public function get enabled() : Boolean
  37.       {
  38.          var _loc1_:Number = 0;
  39.          var _loc2_:int = numRadioButtons;
  40.          var _loc3_:int = 0;
  41.          while(_loc3_ < _loc2_)
  42.          {
  43.             _loc1_ += getRadioButtonAt(_loc3_).enabled;
  44.             _loc3_++;
  45.          }
  46.          if(_loc1_ == 0)
  47.          {
  48.             return false;
  49.          }
  50.          if(_loc1_ == _loc2_)
  51.          {
  52.             return true;
  53.          }
  54.          return false;
  55.       }
  56.       
  57.       public function set enabled(param1:Boolean) : void
  58.       {
  59.          var _loc2_:int = numRadioButtons;
  60.          var _loc3_:int = 0;
  61.          while(_loc3_ < _loc2_)
  62.          {
  63.             getRadioButtonAt(_loc3_).enabled = param1;
  64.             _loc3_++;
  65.          }
  66.          dispatchEvent(new Event("enabledChanged"));
  67.       }
  68.       
  69.       private function radioButton_removedHandler(param1:Event) : void
  70.       {
  71.          var _loc2_:RadioButton = param1.target as RadioButton;
  72.          if(_loc2_)
  73.          {
  74.             _loc2_.removeEventListener(Event.REMOVED,radioButton_removedHandler);
  75.             mx_internal::removeInstance(RadioButton(param1.target));
  76.          }
  77.       }
  78.       
  79.       public function set selectedValue(param1:Object) : void
  80.       {
  81.          var _loc4_:RadioButton = null;
  82.          _selectedValue = param1;
  83.          var _loc2_:int = numRadioButtons;
  84.          var _loc3_:int = 0;
  85.          while(_loc3_ < _loc2_)
  86.          {
  87.             _loc4_ = getRadioButtonAt(_loc3_);
  88.             if(_loc4_.value == param1 || _loc4_.label == param1)
  89.             {
  90.                changeSelection(_loc3_,false);
  91.                break;
  92.             }
  93.             _loc3_++;
  94.          }
  95.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  96.       }
  97.       
  98.       private function getValue() : String
  99.       {
  100.          if(selection)
  101.          {
  102.             return selection.value && selection.value is String && String(selection.value).length != 0 ? String(selection.value) : selection.label;
  103.          }
  104.          return null;
  105.       }
  106.       
  107.       [Bindable("labelPlacementChanged")]
  108.       public function get labelPlacement() : String
  109.       {
  110.          return _labelPlacement;
  111.       }
  112.       
  113.       [Bindable("valueCommit")]
  114.       [Bindable("change")]
  115.       public function get selection() : RadioButton
  116.       {
  117.          return _selection;
  118.       }
  119.       
  120.       [Bindable("valueCommit")]
  121.       [Bindable("change")]
  122.       public function get selectedValue() : Object
  123.       {
  124.          if(selection)
  125.          {
  126.             return selection.value != null ? selection.value : selection.label;
  127.          }
  128.          return null;
  129.       }
  130.       
  131.       public function set selection(param1:RadioButton) : void
  132.       {
  133.          mx_internal::setSelection(param1,false);
  134.       }
  135.       
  136.       mx_internal function setSelection(param1:RadioButton, param2:Boolean = true) : void
  137.       {
  138.          var _loc3_:int = 0;
  139.          var _loc4_:int = 0;
  140.          if(param1 == null && _selection != null)
  141.          {
  142.             _selection.selected = false;
  143.             _selection = null;
  144.             if(param2)
  145.             {
  146.                dispatchEvent(new Event(Event.CHANGE));
  147.             }
  148.          }
  149.          else
  150.          {
  151.             _loc3_ = numRadioButtons;
  152.             _loc4_ = 0;
  153.             while(_loc4_ < _loc3_)
  154.             {
  155.                if(param1 == getRadioButtonAt(_loc4_))
  156.                {
  157.                   changeSelection(_loc4_,param2);
  158.                   break;
  159.                }
  160.                _loc4_++;
  161.             }
  162.          }
  163.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  164.       }
  165.       
  166.       public function initialized(param1:Object, param2:String) : void
  167.       {
  168.          this.document = !!param1 ? IFlexDisplayObject(param1) : IFlexDisplayObject(Application.application);
  169.       }
  170.       
  171.       mx_internal function addInstance(param1:RadioButton) : void
  172.       {
  173.          param1.mx_internal::indexNumber = indexNumber++;
  174.          param1.addEventListener(Event.REMOVED,radioButton_removedHandler);
  175.          radioButtons.push(param1);
  176.          if(_selectedValue != null)
  177.          {
  178.             selectedValue = _selectedValue;
  179.          }
  180.          dispatchEvent(new Event("numRadioButtonsChanged"));
  181.       }
  182.       
  183.       public function set labelPlacement(param1:String) : void
  184.       {
  185.          _labelPlacement = param1;
  186.          var _loc2_:int = numRadioButtons;
  187.          var _loc3_:int = 0;
  188.          while(_loc3_ < _loc2_)
  189.          {
  190.             getRadioButtonAt(_loc3_).labelPlacement = param1;
  191.             _loc3_++;
  192.          }
  193.       }
  194.       
  195.       [Bindable("numRadioButtonsChanged")]
  196.       public function get numRadioButtons() : int
  197.       {
  198.          return radioButtons.length;
  199.       }
  200.       
  201.       public function getRadioButtonAt(param1:int) : RadioButton
  202.       {
  203.          return RadioButton(radioButtons[param1]);
  204.       }
  205.       
  206.       mx_internal function removeInstance(param1:RadioButton) : void
  207.       {
  208.          var _loc2_:Boolean = false;
  209.          var _loc3_:int = 0;
  210.          var _loc4_:RadioButton = null;
  211.          if(param1)
  212.          {
  213.             _loc2_ = false;
  214.             _loc3_ = 0;
  215.             while(_loc3_ < numRadioButtons)
  216.             {
  217.                _loc4_ = getRadioButtonAt(_loc3_);
  218.                if(_loc2_)
  219.                {
  220.                   --_loc4_.mx_internal::indexNumber;
  221.                }
  222.                else if(_loc4_ == param1)
  223.                {
  224.                   _loc4_.group = null;
  225.                   if(param1 == _selection)
  226.                   {
  227.                      _selection = null;
  228.                   }
  229.                   radioButtons.splice(_loc3_,1);
  230.                   _loc2_ = true;
  231.                   --indexNumber;
  232.                   _loc3_--;
  233.                }
  234.                _loc3_++;
  235.             }
  236.             if(_loc2_)
  237.             {
  238.                dispatchEvent(new Event("numRadioButtonsChanged"));
  239.             }
  240.          }
  241.       }
  242.       
  243.       private function changeSelection(param1:int, param2:Boolean = true) : void
  244.       {
  245.          if(getRadioButtonAt(param1))
  246.          {
  247.             if(selection)
  248.             {
  249.                selection.selected = false;
  250.             }
  251.             _selection = getRadioButtonAt(param1);
  252.             _selection.selected = true;
  253.             if(param2)
  254.             {
  255.                dispatchEvent(new Event(Event.CHANGE));
  256.             }
  257.          }
  258.       }
  259.    }
  260. }
  261.  
  262.